package com.zgis.module.db.service.impl;

import com.zgis.module.bas.bean.CxEntity;
import com.zgis.module.db.interfaces.ICxEntity;
import com.zgis.module.db.service.RedisCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Redis版本的Entity管理实现
 */
@Slf4j
@Service("redisCxEntityImpl")
public class RedisCxEntityImpl implements ICxEntity
{

    @Resource
    private RedisCacheService redisCacheService;

    @Override
    public CxEntity queryEntity(String major, String minor) throws Exception {
        CxEntity entity = redisCacheService.getEntityByMajorMinor(major, minor);
        if (entity == null) {
            throw new Exception("未找到Entity: major=" + major + ", minor=" + minor);
        }
        return entity;
    }

    @Override
    public CxEntity queryEntity(String name) throws Exception {
        CxEntity entity = redisCacheService.getEntityByName(name);
        if (entity == null) {
            throw new Exception("未找到Entity: name=" + name);
        }
        return entity;
    }
}
